package com.example.lvsuo.utils;

import com.example.lvsuo.modal.Constant;
import com.example.lvsuo.modal.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

//@ControllerAdvice
@Slf4j
public class ExceptionHandlerUtils {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Result Handler(HttpServletResponse re, Exception e){
        log.info("error："+(e.getCause()==null?e.getMessage():e.getCause().getMessage()));
        Result result = new Result();
        result.put("status", Constant.ERROR.getValue());
        result.put("error",e.getCause()==null?e.getMessage():e.getCause().getMessage());
        return result;
    }
}
